﻿namespace DimensionsHelper.Client.WinUi.Views;

public sealed partial class TableReplacementsPage : Page
{
    public TableReplacementsPage()
    {
        ViewModel = App.GetService<TableReplacementsViewModel>();
        InitializeComponent();
    }

    public TableReplacementsViewModel ViewModel
    {
        get;
    }


    private void DeleteMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
    {
        if (ReplacementDataGrid.SelectedItems == null)
        {
            return;
        }

        object[] selected = [.. ReplacementDataGrid.SelectedItems];

        foreach (object? item in selected)
        {
            if (item is StringPair pair)
            {
                ViewModel.Source.Remove(pair);
            }
        }
    }
}